home *** CD-ROM | disk | FTP | other *** search
- Path: ub239.dialup.uwa.edu.au!localhost!prye
- From: prye@cyllene.uwa.edu.au (Peter Rye)
- Newsgroups: comp.lang.c++
- Subject: Re: returning an array from function
- Date: 08 Apr 1996 06:49:15 GMT
- Organization: The University of Western Australia
- Message-ID: <PRYE.96Apr8144915@cyllene.uwa.edu.au>
- References: <4jstd8$kh0@news1.sunbelt.net>
- <Pine.A32.3.91.960407035313.115982E-100000@magritte.its.rpi.edu>
- NNTP-Posting-Host: ub239.dialup.uwa.edu.au
- In-reply-to: Kengo Hashimoto's message of Sun, 7 Apr 1996 03:56:27 -0400
- X-Mailer: GNU Emacs 19.28
-
- >>>>> "Kengo" == Kengo Hashimoto <hashik@rpi.edu> writes:
-
- Kengo> Just do a call-by-reference to the array, or return a
- Kengo> pointer to the first member of the array. Here are
- Kengo> examples:
-
- Kengo> void foo(int &[]); // just pass the array in there,
-
- This declares the argument as an array of references to int.
- I believe this is not legal.
-
- Kengo> manipulate it // within foo(), and the original copy would
- Kengo> be // modified as well.
-
- An array argument to a function decays to a pointer to the first element
- of the array. A reference is not needed to modify the original copy.
-
- Kengo> returning a pointer: int *foo();
-
- Kengo> int bar[arraysize];
-
- Kengo> bar = foo();
-
- You can't do this.
- An array name is not an l-value. (ie: can't be assigned to).
-
- Kengo> foo() { foo2[arraysize]; return &(foo2[0]); }
-
- This is very naughty.
- foo2[] is local to the function foo.
- ie: it will not exist when the function returns (at least you shouldn't
- assume that it will exist.)
-
-
- --
- Peter Rye prye@cyllene.uwa.edu.au, prye@ichr.uwa.edu.au
- Respiratory Research Fellow, Princess Margaret Hospital for Children
- Perth, Western Australia Ph: +61 (09) 340 8985, Fax: +61 (09) 388 2097
- ** Smoking areas in restaurants are like peeing areas in swimming pools. **
-